#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/tests/stats"

stats = LKP::Stats.new

result = {}

while (line = $stdin.gets)
  case line
  when /(32|64)\):\s+(PASS|FAIL|ignored by lkp)/
    name = "#{$1}bit.#{line.split('(')[0].rstrip.tr('[ .]', '_')}".downcase
    res = $2.tr(' ', '_').downcase
    ret = "#{name}.#{res}"
    ret = "#{name}_again.#{res}" if (line =~ /[xB|xBDT]\.linkshare/) && result.key?(ret)
    result[ret] = 1
    stats.add_test_result line, name, res
  when /(32|64)\):\s+Bad/
    ret = "eid.#{$1}bit.#{line.split('(')[0].rstrip.tr('[ .]', '_')}.bad_configuration".downcase
    stats.add_id ret, 1
  when /(32|64)\):\s+/
    ret = "eid.#{$1}bit.#{line.split('(')[0].rstrip.tr('[ .]', '_')}.killed_by_signal".downcase
    stats.add_id ret, 1
  end
end

stats.dump
